package cn.wolfcode.mongo.service.impl;

import cn.wolfcode.mongo.domain.User;
import cn.wolfcode.mongo.repositroy.UserRepository;
import cn.wolfcode.mongo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Optional;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserRepository userRepository;


    @Override
    public void save(User user) {
        userRepository.save(user);
    }

    @Override
    public void delete(String id) {
        userRepository.deleteById(id);
    }

    @Override
    public void update(User user) {
        userRepository.save(user);
    }

    @Override
//    public User get(String id) {
//        Optional<User> optional = userRepository.findById(id);
//        return  optional.get();
//    }


    public User get(String id) {
        return userRepository.findById(id).get();
    }

    @Override
    public List<User> listAll() {
        return userRepository.findAll();
    }

    @Override
    public User findByName(String name) {
        return userRepository.findByName(name);
    }

    @Override
    public List<User> findByNameOrAge(String name, Integer age) {
        return userRepository.findByNameOrAge(name,age);
    }

    @Override
    public List<User> findByNameAndAge(String name, Integer age) {
        return userRepository.findByNameAndAge(name,age);
    }

    @Override
    public List<User> findByAgeBetween(Integer min, Integer max) {
        return userRepository.findByAgeBetween(min,max);
    }

    @Override
    public List<User> findByAgeLessThan(Integer age) {
        return userRepository.findByAgeLessThan(age);
    }

    @Override
    public List<User> findByAgeGreaterThan(Integer age) {
        return userRepository.findByAgeGreaterThan(age);
    }

    @Override
    public List<User> findByNameIsNull() {
        return userRepository.findByNameIsNull();
    }

    @Override
    public List<User> findByNameLike(String str) {
        return userRepository.findByNameLike(str);
    }

    @Override
    public List<User> findByNameStartingWith(String d) {
        return userRepository.findByNameStartingWith(d);
    }


    @Override
    public List<User> findByOrderByAge() {
        return userRepository.findByOrderByAge();
    }

    @Override
    public List<User> findByOrderByAgeDesc() {
        return userRepository.findByOrderByAgeDesc();
    }

    @Override
    public List<User> findByNameNot(String str) {
        return userRepository.findByNameNot(str);
    }

    @Override
    public List<User> findByAgeIn(List<Integer> ages) {
        return userRepository.findByAgeIn(ages);
    }
}
